//      https://www.nowcoder.com/practice/6a7b2b6c9e3a4f56b1db9f8ca08d889b




#include <iostream>
#include <vector>
#include <climits>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    vector<long long> arr(n + 1, 0);
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];

    vector<vector<long long>> dp(n + 1, vector<long long>(k, LLONG_MIN));
    dp[0][0] = 0;

    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < k; ++j)
            dp[i][(j + arr[i]) % k] = max(dp[i - 1][j] + arr[i], dp[i - 1][(j + arr[i]) % k]);

    if (dp[n][0] <= 0)
        cout << -1 << endl;
    else
        cout << dp[n][0] << endl;
    return 0;
}
